package zheezes.protocol.impl.gbw.format;

public class DataForm34 extends DataForm {
	public static final int SIZE = 1;
	
	private byte data = 0x00;
	
	@Override
	public int sizeof() {
		return SIZE;
	}
	
	@Override
	public int getBytes(byte[] buf, int offset) {
		int idx = offset;
		buf[idx++] = data;
		return idx - offset;
	}

	@Override
	public int setBytes(byte[] buf, int offset) {
		int idx = offset;
		data = buf[idx++];
		return idx - offset;
	}
	
	public int getSymbol() {
		return (data >> 7) & 0x01;
	}
	
	public void setSymbol(int symbol) {
		switch (symbol) {
		case 0:
			data &= 0x7F;
			break;
		case 1:
			data |= 0x80;
			break;
		}
	}
	
	public int getAmount() {
		return data & 0x7F;
	}
	
	public void setAmount(int amount) {
		if (getSymbol() == 0) {
			if (amount > 0 && amount < 128) {
				data = (byte) ((data & 0x80) | amount);
			}
		}
	}
}
